<?php
	class UserAction extends BaseAction{
		public function index()
		{
			$user = M("User");
			import("ORG.Util.Page");
			$count = $user->count();
			$page = new Page($count,c('PAGESIZE'));
			$show = $page->show();
			$data = $user->limit($page->firstRow.','.$page->listRows)
							->field("user,id,login_time,email")
							->select();
			$this->assign("list",$data);
			$this->assign('page',$show);
			$this->display();
		}
		
		public function add(){
			$face = array();//头像图片名
			for($i = 1; $i < 10; $i++)
				$face[$i] = '0'.$i;
			for($i = 10; $i < 25; $i++)
				$face[$i] = $i;
			$this->assign('face',$face);
			$this->display();
		}
		
		public function insert(){
			$user = D("User");
			if($user->create())
			{
				if($user->add())
				{
					$this->assign("jumpUrl","__URL__");
					$this->success("添加成功！");
				}else{
					$this->error("添加失败！");
				}
			}else{
				$this->error($user->getError());
			}			
		}
		
		public function edit()
		{
			if(!empty($_GET['id']))
			{
				$user = M("User");
				$data = $user->getById($_GET['id']);
// 				var_dump($data);
				if(null == $data)
					$this->error("请确认要修改的会员ID合法！");
				$face = array();//头像图片名
				for($i = 1; $i < 10; $i++)
					$face[$i] = '0'.$i;
				for($i = 10; $i < 25; $i++)
					$face[$i] = $i;
				$this->assign('face',$face);
				$this->assign('user',$data);
				$this->display();
				
			}else{
				$this->error("请选择要修改的会员！");
			}
		}
		
		public function update()
		{
			$user = D('User');
			if($user->create()){
				if($user->save()){
					$this->success("更新成功！");
				}else{
					$this->error("因为数据没变化或更新失败！");
				}
			}else{
				$this->error($user->getError());
			}
		
		}
		
		public function delete()
		{
			if(!empty($_GET['id']))
			{
				$user = M("User");
				if($user->delete($_GET['id'])){
					$this->success("删除会员成功!");
				}else{
					$this->error("删除会员失败!");
				}
			}else{
				$this->error("请选择要删除的会员！");
			}
		}
	}
?>